#ifndef USER_IFX_CFG_TRAP_H_
#define USER_IFX_CFG_TRAP_H_

#include "Ifx_Types.h"
#include "IfxCpu_Intrinsics.h"
#include "cpuport.h"

// 添加总线错误处理钩子 - 仅记录不停止
#define IFX_CFG_CPU_TRAP_BE_HOOK(trapWatch) \
    do { \
        rt_kprintf("[TRAP] Bus Error: TIN=0x%x, PC=0x%x, A10=0x%x\n", \
                   trapWatch.tId, trapWatch.tAddr, trapWatch.tAddr); \
        rt_kprintf("[TRAP] Current thread: %s\n", \
                   rt_thread_self() ? rt_thread_self()->name : "NULL"); \
        /* 不停止执行，继续运行 */ \
    } while(0)

IFX_INLINE void tricore_trap_yield_for_task(IfxCpu_Trap trapInfo)
{
  switch(trapInfo.tId)
  {
    case 0:
        trigger_scheduling();
      break;

    default:
      /* Unimplemented trap called. */
      rt_kprintf("[TRAP] Unimplemented syscall: %d\n", trapInfo.tId);
      break;
  }
}

#define IFX_CFG_CPU_TRAP_SYSCALL_CPU0_HOOK(trapInfo)  tricore_trap_yield_for_task(trapInfo)

#endif /* USER_IFX_CFG_TRAP_H_ */
